#version 430

in vec3 worldPos;
in vec3 worldNormal;
in vec2 texcoord;

out vec4 fragColor;

uniform vec3 cameraPos;
uniform vec3 lightDir;

layout(binding = 0) uniform sampler2D samp;

void main()
{
	vec3 normal = normalize(worldNormal);
	vec3 viewDir = normalize(cameraPos - worldPos);


	vec3 ambient = vec3(0.3, 0.3, 0.3);

	vec3 lightDirection = normalize(-lightDir);
	vec3 diffuse = max(dot(lightDirection, normal), 0.0) * vec3(1, 1, 1);

	vec3 reflect = normalize(reflect(-lightDirection, normal));
	vec3 specular = pow(max(dot(viewDir, reflect), 0.0), 1000) * vec3(1, 1, 1);

	vec4 temp = vec4(ambient + diffuse + specular, 1.0f);

	fragColor = texture(samp, texcoord) * temp;
}